package com.zoe.onelink.auth.registry;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2022</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2022-03-30
 */
@Slf4j
public class OnelinkKnife4jOauth2DocRegistry implements BeanDefinitionRegistryPostProcessor {

    public static final String BEAN_PREFIX = "ONELINK_DOCKET_";

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        String groupName = "oauth2";
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .enable(true)
                .groupName(groupName)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.zoe.onelink.auth.endpoint"))
                .paths(PathSelectors.any())
                .build();
        AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(Docket.class, () -> docket)
                .getBeanDefinition();
        registry.registerBeanDefinition(BEAN_PREFIX + groupName, beanDefinition);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    }
}
